package pku.ss.movieSystem.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import pku.ss.movieSystem.common.PaginationSupport;
import pku.ss.movieSystem.common.Utils;
import pku.ss.movieSystem.services.IMovieService;

public class MoreLatestMoviesAction extends Action{

	private IMovieService movieService;

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		try {
			response.setContentType("text/html; charset=utf-8");
			request.setCharacterEncoding("utf8");
			response.setCharacterEncoding("utf8");
			
			int startIndex = Integer.parseInt(request.getParameter("startIndex"));
			PaginationSupport ps = movieService.findLatestMovies(startIndex, -1);
			
			if(ps != null) {
				
				Utils.setRequestAttr(request, ps, startIndex, "", "", null, "moreLatestMovies");
			}
			
			return mapping.findForward("moreLatestMovies");
		}catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	
	}
	
	public void setMovieService(IMovieService movieService) {
		this.movieService = movieService;
	}
}
